﻿using System;
using System.Windows.Forms;

namespace ClassLibrary {
    //http://stackoverflow.com/questions/605920/reasons-for-why-a-winforms-label-does-not-want-to-be-transparent
    public class TransparentLabel : Label {
        public TransparentLabel() {
            this.SetStyle(ControlStyles.Opaque, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
        }

        protected override CreateParams CreateParams {
            get {
                CreateParams parms = base.CreateParams;
                parms.ExStyle |= 0x20;  // Turn on WS_EX_TRANSPARENT
                return parms;
            }
        }

        public override string Text {
            get { return base.Text; }
            set {  
                base.Text = value;
                if (this.Parent != null) {
                    this.Parent.Refresh();
                }
            }
        }
    }
}
